package com.deliveryservicesystem.app.validation;

import com.jgoodies.binding.value.AbstractValueModel;
import com.jgoodies.common.base.Strings;
import com.jgoodies.validation.ValidationResult;
import com.jgoodies.validation.Validator;

/**
 * File Name: ProductValidator.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.app.validation
 * Author: Lance
 * Date: Jun 29, 2012
 * Editor:
 */
public class SupplierValidator extends AbstractValueModel implements Validator<ValidationResult>
{

    private static final long serialVersionUID = 1L;
    private String supplierName;
    private String supplierContact;
    private String supplierAddress;

    public SupplierValidator(String supplierName, String supplierContact, String supplierAddress)
    {
        this.supplierName = supplierName;
        this.supplierContact = supplierContact;
        this.supplierAddress = supplierAddress;
    }

    public String getSupplierAddress()
    {
        return supplierAddress;
    }

    public void setSupplierAddress(String supplierAddress)
    {
        this.supplierAddress = supplierAddress;
    }

    public String getSupplierContact()
    {
        return supplierContact;
    }

    public void setSupplierContact(String supplierContact)
    {
        this.supplierContact = supplierContact;
    }

    public String getSupplierName()
    {
        return supplierName;
    }

    public void setSupplierName(String supplierName)
    {
        this.supplierName = supplierName;
    }

    @Override
    public Object getValue()
    {
        return this;
    }

    @Override
    public void setValue(Object newValue)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ValidationResult validate(ValidationResult validationTarget)
    {
        if (Strings.isEmpty(supplierName.trim()))
        {
            validationTarget.addError("Supplier name required");
        }
        if (Strings.isEmpty(supplierContact.trim()))
        {
            validationTarget.addError("Supplier contact required");
        }
        if (Strings.isEmpty(supplierAddress.trim()))
        {
            validationTarget.addError("Supplier address required");
        }
        return validationTarget;
    }
}
